<?php
/**
 * @author Mazvv
 * @package LoginManagement
 */
class Login extends CRM_Controller {

	/**
	 * @var array
	 */
	private $objectsList = array();
	
	public function __construct()
	{
		parent::__construct();
		/* TODO: ��������� ��������� ����� ������������ */
		
		$this->lang->load('login');
		$this->load->library('login_module');
	}
	
	/**
	 * @author Mazvv
	 * @param $m_Name
	 * @return void
	 */
	public function _remap($m_Name){
		switch ($m_Name){
			case 'l': {$this->_login();break;}
			case 'c': {$this->_setnewpasswd();break;}
			default: $this->_index();
		}
	}
	
	
	/**
	 * @param void
	 * @return void
	 */
	protected function _index(){
		$this->objectsList['M1_LOGIN_FORM_OBJECT']=$this->login_module->RenderLoginForm();
		$this->load->view('layouts/login_layout', $this->objectsList);
	}
	
	/**
	 * @author Mazvv
	 * @param void
	 * @return void
	 */
	private function _login(){
		$today = date('Y-m-d');
		$result = $this->login_module->CheckUser();
		if(!$result) {
			$this->objectsList['M1_LOGIN_FORM_OBJECT'] = $this->login_module->RenderLoginForm(True);
			$this->load->view('layouts/login_layout', $this->objectsList);
		} elseif($result->edate_passwd <= $today) {
			$this->_enddate();
		} else {
			$this->login_module->SetUserSession($result);
			$this->user->UpdateUserData();
			if($result->chdate_passwd <= $today) {
				$this->_chdate();
			} else redirect('welcome', 'refresh');
		}
	}
	
	/**
	 * ��������� ����� �������� ������
	 * 
	 * @author Mazvv
	 * @param void
	 * @return void
	 */
	private function _enddate(){
		$this->objectsList['M1_LOGIN_FORM_OBJECT'] = $this->login_module->RenderEndExpDate();
		$this->load->view('layouts/login_layout', $this->objectsList);
	}
	

	/**
	 * ��������� ����������� �� ����� ������
	 * 
	 * @author Mazvv
	 * @param void
	 * @return void
	 */
	private function _chdate(){
		$this->objectsList['M1_LOGIN_FORM_OBJECT'] = $this->login_module->RenderChangePasswd();
		$this->load->view('layouts/login_layout', $this->objectsList);
	}

	/**
	 * ��������� ������ ������ ������������
	 * 
	 * @author Mazvv
	 * @param void
	 * @return void
	 */
	private function _setnewpasswd() {
		$this->objectsList['M1_LOGIN_FORM_OBJECT'] = $this->login_module->ChangePasswdProcess();
		$this->load->view('layouts/login_layout', $this->objectsList);
	}
	
}
?>